package cn.hpclub.server.model.esopdemo;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import com.jfinal.ext.plugin.tablebind.TableBind;
import com.jfinal.kit.StrKit;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Model;
import com.jfinal.plugin.activerecord.Record;

@TableBind(tableName = "esopdemo_idc")
public class Idc extends Model<Idc> implements Serializable{

    private static final long serialVersionUID = -57555379613217315L;

    public static final Idc   dao              = new Idc();

    public List<Record> getOpponentList(String group_name, String group_no, String operator){
        List<Object> paras = new ArrayList<Object>();

        String sql = "select * from esopdemo_idc "
                + " where (bus_type = 'IDC' or bus_type = '专线' or bus_type = '集团电话' or bus_type = '物联网') ";

        if(null != group_name && !"".equals(group_name)){
            sql += " and group_name = ? ";
            paras.add(group_name);
        }

        if(null != group_no && !"".equals(group_no)){
            sql += " and group_no = ? ";
            paras.add(group_no);
        }

        if(null != operator && !"".equals(operator)){
            sql += " and operator = ? ";
            paras.add(operator);
        }

        sql += " order by created_time desc ";

        List<Record> idcList = Db.find(sql, paras.toArray());

        return idcList;
    }

    public List<Record> getOpportunityList(String opp_id, String opp_type, String opp_part, String group_no){
        List<Object> paras = new ArrayList<Object>();

        String sql = "select * from esopdemo_idc "
                + " where (bus_type = '移动400' or bus_type = '集团短信' or bus_type = '语音专线' or bus_type = '数据专线' or bus_type = '其他产品')";

        if(StrKit.notBlank(opp_type)){
            sql += " and bus_type = ? ";
            paras.add(opp_type);
        }
        if(StrKit.notBlank(opp_id)){
            sql += " and id = ? ";
            paras.add(opp_id);
        }
        if(StrKit.notBlank(opp_part)){
            sql += " and k2 = ? ";
            paras.add(opp_part);
        }
        if(StrKit.notBlank(group_no)){
            sql += " and group_no = ? ";
            paras.add(group_no);
        }

        // if(StrKit.notBlank(opp_type)){
        // sql += " bus_type = ? ";
        // paras.add(opp_type);
        //
        // if(StrKit.notBlank(opp_id)){
        // sql += " and id = ? ";
        // paras.add(opp_id);
        // }
        // if(StrKit.notBlank(opp_part)){
        // sql += " and k2 = ? ";
        // paras.add(opp_part);
        // }
        // } else{
        // if(StrKit.isBlank(opp_id) && StrKit.isBlank(opp_part)){
        // sql += " (bus_type = '移动400' or bus_type = '集团短信' or bus_type =
        // '语音专线' or bus_type = '数据专线' or bus_type = '其他产品') ";
        // } else if(StrKit.notBlank(opp_id)){
        // sql += " id = ? ";
        // paras.add(opp_id);
        //
        // if(StrKit.notBlank(opp_part)){
        // sql += " and k2 = ? ";
        // paras.add(opp_part);
        // }
        // } else if(StrKit.notBlank(opp_part)){
        // sql += " k2 = ? ";
        // paras.add(opp_part);
        // }
        // }

        List<Record> idcList = Db.find(sql, paras.toArray());

        return idcList;
    }
}
